<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片处理</title>
    <!-- 引入Element UI样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入Vue和Element UI -->
    <script src="https://unpkg.com/vue@2.6.14/dist/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!-- 引入axios用于HTTP请求 -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <style>
        /* 添加CSS变量定义 */
        :root {
            --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
            --secondary-gradient: linear-gradient(45deg, #f0f9ff 0%, #faf5ff 100%);
            --card-bg: rgba(255, 255, 255, 0.9);
            --card-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
            --text-primary: #1f2937;
            --text-secondary: #6b7280;
            --border-radius: 16px;
        }

        body {
            margin: 0;
            padding: 0;
            min-height: 100vh;
            font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
            overflow-x: hidden;
            position: relative;
        }

        /* 多层背景系统 */
        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -3;
            /* 主渐变背景 */
            background: linear-gradient(135deg,
            #f8fafc 0%,
            #e2e8f0 25%,
            #cbd5e1 50%,
            #94a3b8 75%,
            #64748b 100%);
        }

        body::after {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -2;
            opacity: 0.6;
            /* 动态几何图案 */
            background-image: radial-gradient(circle at 20% 30%, rgba(99, 102, 241, 0.1) 0%, transparent 25%),
            radial-gradient(circle at 80% 20%, rgba(139, 92, 246, 0.08) 0%, transparent 30%),
            radial-gradient(circle at 60% 70%, rgba(168, 85, 247, 0.06) 0%, transparent 25%),
            radial-gradient(circle at 10% 80%, rgba(59, 130, 246, 0.05) 0%, transparent 20%),
            linear-gradient(45deg, transparent 49%, rgba(255, 255, 255, 0.02) 50%, transparent 51%);
            background-size: 800px 800px, 600px 600px, 1000px 1000px, 400px 400px, 100px 100px;
            animation: backgroundFloat 20s ease-in-out infinite;
        }

        /* 浮动动画 */
        @keyframes backgroundFloat {
            0%, 100% {
                transform: translate(0, 0) rotate(0deg);
                opacity: 0.6;
            }
            25% {
                transform: translate(-20px, -10px) rotate(0.5deg);
                opacity: 0.8;
            }
            50% {
                transform: translate(10px, -5px) rotate(-0.3deg);
                opacity: 0.7;
            }
            75% {
                transform: translate(-5px, 10px) rotate(0.2deg);
                opacity: 0.9;
            }
        }

        /* 装饰性几何元素 */
        .background-decoration {
            position: fixed;
            z-index: -1;
            pointer-events: none;
        }

        .bg-circle-1 {
            width: 300px;
            height: 300px;
            background: radial-gradient(circle, rgba(99, 102, 241, 0.05) 0%, transparent 70%);
            border-radius: 50%;
            top: 10%;
            right: 10%;
            animation: float1 8s ease-in-out infinite;
        }

        .bg-circle-2 {
            width: 200px;
            height: 200px;
            background: radial-gradient(circle, rgba(139, 92, 246, 0.04) 0%, transparent 70%);
            border-radius: 50%;
            bottom: 20%;
            left: 5%;
            animation: float2 10s ease-in-out infinite;
        }

        .bg-triangle {
            width: 0;
            height: 0;
            border-left: 100px solid transparent;
            border-right: 100px solid transparent;
            border-bottom: 150px solid rgba(168, 85, 247, 0.03);
            top: 60%;
            right: 20%;
            animation: float3 12s ease-in-out infinite;
        }

        @keyframes float1 {
            0%, 100% {
                transform: translateY(0px) rotate(0deg);
            }
            50% {
                transform: translateY(-20px) rotate(180deg);
            }
        }

        @keyframes float2 {
            0%, 100% {
                transform: translateX(0px) scale(1);
            }
            50% {
                transform: translateX(30px) scale(1.1);
            }
        }

        @keyframes float3 {
            0%, 100% {
                transform: translateY(0px) rotate(0deg);
            }
            33% {
                transform: translateY(-15px) rotate(120deg);
            }
            66% {
                transform: translateY(15px) rotate(240deg);
            }
        }

        .app-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 40px 20px;
            position: relative;
            z-index: 1;
            display: grid;
            grid-template-columns: 1fr 1fr;
            grid-template-rows: auto auto;
            gap: 30px;
            align-items: stretch;
        }

        /* 主容器进入动画 */
        .app-container {
            animation: containerEntrance 1s ease-out forwards;
            opacity: 0;
            transform: translateY(30px);
        }

        /* 上传卡片占据第一行左侧 */
        .upload-card {
            grid-column: 1;
            grid-row: 1;
            display: flex;
            flex-direction: column;
        }

        /* 设置卡片占据第一行右侧 */
        .settings-card {
            grid-column: 2;
            grid-row: 1;
            display: flex;
            flex-direction: column;
        }

        /* 结果卡片占据第二行全宽 */
        .result-card {
            grid-column: 1 / -1;
            grid-row: 2;
        }

        @keyframes containerEntrance {
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .section-card {
            margin-bottom: 30px;
            border-radius: var(--border-radius);
            border: 1px solid rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            background: linear-gradient(145deg,
            rgba(255, 255, 255, 0.95) 0%,
            rgba(248, 250, 252, 0.9) 50%,
            rgba(241, 245, 249, 0.85) 100%);
            box-shadow: var(--card-shadow);
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            overflow: hidden;
        }

        /* 为不同卡片添加微妙的色彩差异 */
        .section-card:nth-child(1) {
            background: linear-gradient(145deg,
            rgba(255, 251, 235, 0.95) 0%,
            rgba(254, 249, 195, 0.9) 50%,
            rgba(252, 211, 77, 0.1) 100%);
            border-color: rgba(252, 211, 77, 0.2);
        }

        .section-card:nth-child(2) {
            background: linear-gradient(145deg,
            rgba(239, 246, 255, 0.95) 0%,
            rgba(219, 234, 254, 0.9) 50%,
            rgba(99, 102, 241, 0.1) 100%);
            border-color: rgba(99, 102, 241, 0.2);
        }

        .section-card:nth-child(3) {
            background: linear-gradient(145deg,
            rgba(245, 243, 255, 0.95) 0%,
            rgba(237, 233, 254, 0.9) 50%,
            rgba(139, 92, 246, 0.1) 100%);
            border-color: rgba(139, 92, 246, 0.2);
        }

        /* 卡片悬停效果 */
        .section-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 32px 64px rgba(0, 0, 0, 0.12);
        }

        .section-card:nth-child(1):hover {
            box-shadow: 0 32px 64px rgba(252, 211, 77, 0.2);
            border-color: rgba(252, 211, 77, 0.3);
        }

        .section-card:nth-child(2):hover {
            box-shadow: 0 32px 64px rgba(99, 102, 241, 0.2);
            border-color: rgba(99, 102, 241, 0.3);
        }

        .section-card:nth-child(3):hover {
            box-shadow: 0 32px 64px rgba(139, 92, 246, 0.2);
            border-color: rgba(139, 92, 246, 0.3);
        }

        /* 卡片光效 */
        .section-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.4),
            transparent);
            transition: left 0.8s;
            z-index: 1;
        }

        .section-card:hover::before {
            left: 100%;
        }

        /* 为卡片添加微妙的纹理 */
        .section-card::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-image: radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.03) 0%, transparent 50%),
            radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.05) 0%, transparent 50%),
            radial-gradient(circle at 40% 40%, rgba(120, 119, 198, 0.02) 0%, transparent 50%);
            pointer-events: none;
            z-index: 0;
        }

        /* 卡片边缘高光效果 - 重新定义阴影 */
        .section-card {
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08),
            inset 0 1px 0 rgba(255, 255, 255, 0.6),
            inset 0 -1px 0 rgba(0, 0, 0, 0.05) !important;
        }

        .section-card:nth-child(1) {
            box-shadow: 0 20px 40px rgba(252, 211, 77, 0.08),
            inset 0 1px 0 rgba(255, 255, 255, 0.6),
            inset 0 -1px 0 rgba(252, 211, 77, 0.1) !important;
        }

        .section-card:nth-child(2) {
            box-shadow: 0 20px 40px rgba(99, 102, 241, 0.08),
            inset 0 1px 0 rgba(255, 255, 255, 0.6),
            inset 0 -1px 0 rgba(99, 102, 241, 0.1) !important;
        }

        .section-card:nth-child(3) {
            box-shadow: 0 20px 40px rgba(139, 92, 246, 0.08),
            inset 0 1px 0 rgba(255, 255, 255, 0.6),
            inset 0 -1px 0 rgba(139, 92, 246, 0.1) !important;
        }

        .section-title {
            font-size: 20px;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 15px;
            position: relative;
            z-index: 2;
        }

        .upload-container {
            text-align: center;
            padding: 30px 20px;
            position: relative;
            z-index: 2;
            background: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(5px);
            border-radius: 0 0 12px 12px;
            flex: 1;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .upload-area-wrapper {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 15px;
        }

        .upload-component {
            display: flex;
            justify-content: center;
        }

        .uploaded-images {
            width: 100%;
        }

        .uploaded-title {
            font-size: 14px;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 15px;
            text-align: left;
            border-bottom: 2px solid rgba(99, 102, 241, 0.2);
            padding-bottom: 8px;
        }

        .image-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
            gap: 15px;
            max-height: 300px;
            overflow-y: auto;
            padding: 10px 0;
        }

        .image-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 8px;
        }

        .image-wrapper {
            position: relative;
            width: 100px;
            height: 100px;
            border-radius: 8px;
            overflow: hidden;
            border: 2px solid #e5e7eb;
            transition: all 0.3s ease;
        }

        .image-wrapper:hover {
            border-color: #6366f1;
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(99, 102, 241, 0.2);
        }

        .uploaded-image {
            width: 100%;
            height: 100%;
            object-fit: cover;
            cursor: pointer;
            transition: transform 0.3s ease;
        }

        .image-wrapper:hover .uploaded-image {
            transform: scale(1.05);
        }

        .image-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .image-wrapper:hover .image-overlay {
            opacity: 1;
        }

        .overlay-btn {
            color: white;
            font-size: 16px;
            padding: 4px;
            border-radius: 4px;
        }

        .overlay-btn:hover {
            background: rgba(255, 255, 255, 0.2);
            color: white;
        }

        .delete-btn:hover {
            background: rgba(239, 68, 68, 0.8);
        }

        .image-name {
            font-size: 12px;
            color: var(--text-secondary);
            text-align: center;
            max-width: 100px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .controls-container {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 30px 20px;
            flex-wrap: wrap;
            position: relative;
            z-index: 2;
            background: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(5px);
            border-radius: 0 0 12px 12px;
            flex: 1;
            align-items: stretch;
        }

        .direction-selector {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .action-button {
            margin-left: 20px;
        }

        .canvas-container {
            text-align: center;
            padding: 40px 30px;
            background: rgba(255, 255, 255, 0.3);
            border-radius: 12px;
            margin-top: 20px;
            backdrop-filter: blur(15px);
            border: 1px solid rgba(255, 255, 255, 0.4);
            transition: all 0.3s ease;
            position: relative;
            z-index: 2;
        }

        .canvas-container:hover {
            background: rgba(255, 255, 255, 0.4);
            transform: translateY(-2px);
        }

        #myCanvas {
            max-width: 100%;
            border: 1px solid #ebeef5;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        }

        .image-preview {
            max-width: 100%;
            max-height: 400px;
            margin: 0 auto;
            display: block;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .result-title {
            text-align: center;
            margin: 20px 0;
            color: #606266;
            font-weight: 500;
        }

        .el-upload--picture-card {
            width: 120px;
            height: 120px;
            line-height: 120px;
            border-radius: 12px;
            border: 2px dashed #d1d5db;
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(10px);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .el-upload--picture-card:hover {
            border-color: #6366f1;
            transform: translateY(-4px);
            box-shadow: 0 12px 25px rgba(99, 102, 241, 0.15);
            background: rgba(255, 255, 255, 0.95);
        }

        .el-upload-list--picture-card .el-upload-list__item {
            width: 120px;
            height: 120px;
            border-radius: 10px;
        }

        @media (max-width: 768px) {
            .controls-container {
                flex-direction: column;
                gap: 15px;
            }

            .direction-selector {
                justify-content: center;
            }

            .action-button {
                margin-left: 0;
            }
        }

        /* 卡片头部样式 */
        .card-header {
            padding: 20px 24px !important;
            border-bottom: 1px solid rgba(229, 231, 235, 0.6);
            background: rgba(255, 255, 255, 0.4);
            border-radius: 16px 16px 0 0;
            position: relative;
            z-index: 2;
            backdrop-filter: blur(10px);
        }

        /* 为不同卡片的头部添加主题色 */
        .section-card:nth-child(1) .card-header {
            background: rgba(255, 251, 235, 0.6);
            border-bottom-color: rgba(252, 211, 77, 0.3);
        }

        .section-card:nth-child(2) .card-header {
            background: rgba(239, 246, 255, 0.6);
            border-bottom-color: rgba(99, 102, 241, 0.3);
        }

        .section-card:nth-child(3) .card-header {
            background: rgba(245, 243, 255, 0.6);
            border-bottom-color: rgba(139, 92, 246, 0.3);
        }

        /* 页面标题 */
        .page-title {
            text-align: center;
            background: var(--primary-gradient);
            background-clip: text;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-size: 36px;
            font-weight: 700;
            margin-bottom: 16px;
            letter-spacing: -0.5px;
            position: relative;
            animation: titleGlow 3s ease-in-out infinite alternate;
        }

        @keyframes titleGlow {
            0% {
                filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.3));
            }
            100% {
                filter: drop-shadow(0 0 30px rgba(139, 92, 246, 0.5));
            }
        }

        /* 页面副标题 */
        .page-subtitle {
            text-align: center;
            color: var(--text-secondary);
            font-size: 18px;
            margin-top: 8px;
            margin-bottom: 50px;
            font-weight: 400;
            opacity: 0.8;
        }

        /* 按钮美化 */
        .el-button--primary {
            background: var(--primary-gradient);
            border: none;
            border-radius: 12px;
            padding: 12px 24px;
            font-weight: 600;
            letter-spacing: 0.5px;
            box-shadow: 0 8px 25px rgba(99, 102, 241, 0.3);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            overflow: hidden;
        }

        .el-button--primary:hover {
            transform: translateY(-3px);
            box-shadow: 0 12px 35px rgba(99, 102, 241, 0.4);
        }

        .el-button--primary:active {
            transform: translateY(-1px);
            box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
        }

        /* 下拉选择器美化 */
        .el-select .el-input__inner {
            border-radius: 8px;
            border: 1px solid rgba(209, 213, 219, 0.8);
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }

        .el-select .el-input__inner:hover {
            border-color: #6366f1;
            box-shadow: 0 4px 12px rgba(99, 102, 241, 0.1);
        }

        /* 卡片动画效果 */
        .section-card {
            animation: cardEntrance 0.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
            opacity: 0;
            transform: translateY(40px) scale(0.95);
        }

        @keyframes cardEntrance {
            to {
                opacity: 1;
                transform: translateY(0) scale(1);
            }
        }

        .section-card:nth-child(1) {
            animation-delay: 0.2s;
        }

        .section-card:nth-child(2) {
            animation-delay: 0.4s;
        }

        .section-card:nth-child(3) {
            animation-delay: 0.6s;
        }

        /* 响应式优化 */
        @media (max-width: 768px) {
            .page-title {
                font-size: 28px;
            }

            .page-subtitle {
                font-size: 16px;
                margin-bottom: 30px;
            }

            .app-container {
                padding: 20px 15px;
                display: flex;
                flex-direction: column;
                gap: 20px;
            }

            .section-card {
                margin-bottom: 0;
            }

            .controls-container {
                flex-direction: column;
                gap: 20px;
                align-items: stretch;
            }

            .action-area {
                align-items: stretch;
            }

            .action-button {
                width: 100%;
                margin-left: 0;
            }

            .result-actions {
                flex-direction: column;
                gap: 8px;
            }
        }

        /* 滚动条美化 */
        ::-webkit-scrollbar {
            width: 8px;
        }

        ::-webkit-scrollbar-track {
            background: rgba(0, 0, 0, 0.1);
            border-radius: 4px;
        }

        ::-webkit-scrollbar-thumb {
            background: var(--primary-gradient);
            border-radius: 4px;
            transition: all 0.3s ease;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: linear-gradient(135deg, #5b5cf6 0%, #7c3aed 100%);
        }

        /* 人性化布局样式 */
        .card-subtitle {
            font-size: 12px;
            color: var(--text-secondary);
            margin-top: 4px;
            opacity: 0.7;
        }

        .upload-area {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 20px;
            height: 100%;
            min-height: 120px;
        }

        .upload-icon {
            font-size: 32px;
            color: #8b5cf6;
            margin-bottom: 8px;
            line-height: 1;
        }

        .upload-text {
            font-size: 14px;
            color: var(--text-primary);
            margin-bottom: 0;
            font-weight: 500;
            line-height: 1;
            text-align: center;
        }

        .upload-hint {
            font-size: 12px;
            color: var(--text-secondary);
            opacity: 0.7;
        }

        .upload-stats {
            margin-top: 15px;
            text-align: center;
        }

        .setting-group {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .setting-label {
            font-size: 14px;
            color: var(--text-primary);
            font-weight: 500;
            margin-bottom: 8px;
            display: block;
        }

        .direction-radio {
            margin-top: 8px;
        }

        .action-area {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .button-hint {
            font-size: 12px;
            color: var(--text-secondary);
            text-align: center;
        }

        .result-actions {
            margin-bottom: 20px;
            display: flex;
            justify-content: center;
            gap: 12px;
        }

        .image-result-container {
            cursor: pointer;
            transition: transform 0.3s ease;
        }

        .image-result-container:hover {
            transform: scale(1.02);
        }

        .loading-container {
            text-align: center;
            padding: 40px 20px;
        }

        .loading-container p {
            margin-top: 15px;
            color: var(--text-secondary);
        }

        /* Dialog 样式优化 */
        .image-preview-dialog {
            position: fixed !important;
            top: 50% !important;
            left: 50% !important;
            transform: translate(-50%, -50%) !important;
            z-index: 2001;
            margin: 0 !important;
        }

        .image-preview-dialog .el-dialog {
            position: relative;
            margin: 0 !important;
            top: 0 !important;
            transform: none !important;
        }

        .image-preview-dialog .el-dialog__wrapper {
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            overflow: auto;
            margin: 0;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .image-preview-dialog .el-dialog__header {
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            border-bottom: 1px solid #e2e8f0;
        }

        .dialog-header {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .dialog-subtitle {
            font-size: 12px;
            color: var(--text-secondary);
            margin-left: auto;
        }

        .dialog-content {
            padding: 20px;
            text-align: center;
            max-height: 70vh;
            overflow: auto;
        }

        .image-container {
            position: relative;
            overflow: hidden;
            border-radius: 12px;
            background: #f8fafc;
        }

        .dialog-image {
            max-width: 100%;
            max-height: 60vh;
            cursor: grab;
            transition: transform 0.3s ease;
            object-fit: contain;
        }

        .dialog-image:active {
            cursor: grabbing;
        }

        .dialog-actions {
            display: flex;
            justify-content: center;
            gap: 12px;
        }

        /* Drawer 样式优化 */
        .download-drawer {
            z-index: 2002 !important;
        }

        .download-drawer .el-drawer {
            position: fixed !important;
            top: 0 !important;
            right: 0 !important;
            height: 100vh !important;
            z-index: 2002;
        }

        .download-drawer .el-drawer__wrapper {
            position: fixed !important;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 2002;
        }

        .download-drawer .el-overlay {
            position: fixed !important;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5) !important;
            z-index: 2001;
        }

        .download-drawer .el-drawer__header {
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            border-bottom: 1px solid #e2e8f0;
            padding: 20px;
        }

        .drawer-content {
            padding: 20px;
            height: 100%;
            overflow-y: auto;
        }

        .preview-section, .settings-section, .actions-section {
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid #f1f5f9;
        }

        .preview-image-container {
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 15px;
            background: #f8fafc;
            border-radius: 8px;
            border: 2px dashed #cbd5e1;
            min-height: 120px;
        }

        .preview-image {
            max-width: 100%;
            max-height: 120px;
            border-radius: 6px;
            object-fit: contain;
        }

        .setting-item {
            margin-bottom: 20px;
        }

        .quality-control {
            margin-top: 8px;
        }

        .quality-slider {
            margin-bottom: 10px;
        }

        .quality-tips {
            display: flex;
            justify-content: space-between;
            margin-top: 5px;
        }

        .tip-item {
            font-size: 11px;
            padding: 2px 6px;
            border-radius: 4px;
            background: #f1f5f9;
            color: var(--text-secondary);
            transition: all 0.3s ease;
        }

        .tip-item.active {
            background: var(--primary-gradient);
            color: white;
        }

        .size-info {
            margin-top: 8px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 32px;
        }

        .action-buttons {
            display: grid;
            grid-template-columns: 1fr;
            gap: 10px;
            margin-bottom: 20px;
        }

        .action-btn {
            width: 100%;
        }

        /* 全局遮罩样式 */
        .v-modal {
            position: fixed !important;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5) !important;
            z-index: 2000;
        }

        /* ElementUI Dialog 遮罩 */
        .el-dialog__wrapper {
            position: fixed !important;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 2001;
        }

        /* ElementUI Drawer 遮罩 */
        .el-drawer__wrapper {
            position: fixed !important;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 2002;
        }

        /* 确保 body 不会被隐藏 */
        body.el-popup-parent--hidden {
            overflow: hidden !important;
        }
    </style>
</head>
<body>
<!-- 背景装饰元素 -->
<div class="background-decoration bg-circle-1"></div>
<div class="background-decoration bg-circle-2"></div>
<div class="background-decoration bg-triangle"></div>

<div id="app">
    <div class="page-title">图片拼接工具</div>
    <div class="page-subtitle">轻松将多张图片拼接成一张完整图片</div>
    <div class="app-container">
        <el-card class="section-card upload-card">
            <div slot="header" class="card-header">
                <i class="el-icon-upload"></i>
                <span class="section-title">📷 图片上传</span>
                <div class="card-subtitle">支持多张图片，拖拽上传更方便</div>
            </div>
            <div class="upload-container">
                <!-- 上传区域 -->
                <div class="upload-area-wrapper">
                    <el-upload
                            action="http://127.0.0.1:9090/editPic"
                            list-type="picture-card"
                            :on-preview="handlePictureCardPreview"
                            :on-remove="handleRemove"
                            :on-change="handleChange"
                            :before-upload="handleBeforeUpload"
                            multiple
                            accept="image/*"
                            :show-file-list="false"
                            class="upload-component">
                        <div class="upload-area">
                            <i class="el-icon-plus upload-icon"></i>
                            <div class="upload-text"></div>
                        </div>
                    </el-upload>
                    <div class="upload-stats" v-if="imageList.length > 0">
                        <el-tag type="success" size="small">已上传 {{ imageList.length }} 张图片</el-tag>
                    </div>
                </div>

                <!-- 已上传图片列表 -->
                <div class="uploaded-images" v-if="imageList.length > 0">
                    <div class="uploaded-title">已上传的图片</div>
                    <div class="image-list">
                        <div
                                v-for="(file, index) in imageList"
                                :key="index"
                                class="image-item">
                            <div class="image-wrapper">
                                <img :src="file.url" class="uploaded-image" @click="handlePictureCardPreview(file)">
                                <div class="image-overlay">
                                    <el-button
                                            type="text"
                                            icon="el-icon-zoom-in"
                                            @click="handlePictureCardPreview(file)"
                                            class="overlay-btn">
                                    </el-button>
                                    <el-button
                                            type="text"
                                            icon="el-icon-delete"
                                            @click="removeImage(index)"
                                            class="overlay-btn delete-btn">
                                    </el-button>
                                </div>
                            </div>
                            <div class="image-name">{{ file.name || '图片' + (index + 1) }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </el-card>

        <el-card class="section-card settings-card">
            <div slot="header" class="card-header">
                <i class="el-icon-setting"></i>
                <span class="section-title">⚙️ 拼接设置</span>
                <div class="card-subtitle">选择合适的拼接方式</div>
            </div>
            <div class="controls-container">
                <div class="setting-group">
                    <label class="setting-label">拼接方向：</label>
                    <el-radio-group v-model="direction" class="direction-radio">
                        <el-radio-button label="hx">
                            <i class="el-icon-right"></i> 横向拼接
                        </el-radio-button>
                        <el-radio-button label="zx">
                            <i class="el-icon-bottom"></i> 纵向拼接
                        </el-radio-button>
                    </el-radio-group>
                </div>
                <div class="action-area">
                    <el-button
                            type="primary"
                            @click="stitchImages"
                            class="action-button"
                            :disabled="imageList.length < 2"
                            :loading="isProcessing"
                            size="medium">
                        <i class="el-icon-magic-stick"></i>
                        {{ isProcessing ? '拼接中...' : '开始拼接' }}
                    </el-button>
                    <div class="button-hint" v-if="imageList.length < 2">
                        至少需要 2 张图片才能拼接
                    </div>
                </div>
            </div>
        </el-card>

        <el-card class="section-card result-card" v-if="stitchedImage || isProcessing">
            <div slot="header" class="card-header">
                <i class="el-icon-picture-outline"></i>
                <span class="section-title">✨ 拼接结果</span>
                <div class="card-subtitle">完成的拼接作品</div>
            </div>
            <div class="canvas-container">
                <div v-if="isProcessing" class="loading-container">
                    <el-progress :percentage="processingProgress" :show-text="false"></el-progress>
                    <p>正在处理中，请稍候...</p>
                </div>
                <div v-else>
                    <div class="result-actions">
                        <el-button type="primary" plain @click="handlePictureCardPreview({url: stitchedImage})">
                            <i class="el-icon-zoom-in"></i> 查看大图
                        </el-button>
                        <el-button type="primary" plain @click="openDig">
                            <i class="el-icon-download"></i> 下载图片
                        </el-button>
                    </div>
                    <div class="image-result-container">
                        <img :src="stitchedImage" class="image-preview" alt="拼接结果"
                             @click="handlePictureCardPreview({url: stitchedImage})">
                    </div>
                </div>
            </div>
        </el-card>
        <el-dialog
                :visible.sync="dialogVisible"
                width="80%"
                :modal-append-to-body="true"
                :close-on-click-modal="true"
                :show-close="true"
                :lock-scroll="true"
                :append-to-body="true"
                :center="true"
                custom-class="image-preview-dialog">
            <div slot="title" class="dialog-header">
                <i class="el-icon-picture-outline"></i>
                <span>图片预览</span>
                <div class="dialog-subtitle">高清大图查看</div>
            </div>
            <div class="dialog-content">
                <div class="image-container">
                    <img
                            :src="dialogImageUrl"
                            alt="图片预览"
                            class="dialog-image"
                            @wheel="handleImageWheel"
                            @mousedown="startDrag"
                            @mousemove="dragImage"
                            @mouseup="endDrag"
                            @mouseleave="endDrag"
                            :style="imageStyle">
                </div>
            </div>
            <span slot="footer" class="dialog-footer">
                <div class="dialog-actions">
                    <el-button @click="resetImageView" icon="el-icon-refresh-left">重置视图</el-button>
                    <el-button @click="downloadCurrentImage" type="primary" icon="el-icon-download">下载图片</el-button>
                    <el-button @click="dialogVisible = false" icon="el-icon-close">关闭</el-button>
                </div>
            </span>
        </el-dialog>
        <el-drawer
                title="📥 图片下载设置"
                :visible.sync="dialogPic"
                direction="rtl"
                :before-close="handleClose"
                :modal="true"
                :modal-append-to-body="true"
                :append-to-body="true"
                :lock-scroll="true"
                size="400px"
                custom-class="download-drawer">
            <div class="drawer-content">
                <!-- 图片预览区域 -->
                <div class="preview-section">
                    <h4 class="section-title">
                        <i class="el-icon-view"></i> 预览效果
                    </h4>
                    <div class="preview-image-container">
                        <img :src="stitchedImage" class="preview-image" alt="预览图">
                    </div>
                </div>

                <!-- 设置区域 -->
                <div class="settings-section">
                    <h4 class="section-title">
                        <i class="el-icon-setting"></i> 压缩设置
                    </h4>

                    <div class="setting-item">
                        <label class="setting-label">图片质量：</label>
                        <div class="quality-control">
                            <el-slider
                                    v-model="quality"
                                    :min="10"
                                    :max="100"
                                    :step="5"
                                    show-input
                                    show-input-controls
                                    @change="handleChangeNumber"
                                    class="quality-slider">
                            </el-slider>
                            <div class="quality-tips">
                                <span class="tip-item" :class="{active: quality >= 80}">高质量</span>
                                <span class="tip-item" :class="{active: quality >= 40 && quality < 80}">中质量</span>
                                <span class="tip-item" :class="{active: quality < 40}">低质量</span>
                            </div>
                        </div>
                    </div>

                    <div class="setting-item" v-if="picSize">
                        <label class="setting-label">估算大小：</label>
                        <div class="size-info">
                            <el-tag size="medium" type="info">{{ picSize }}</el-tag>
                        </div>
                    </div>
                </div>

                <!-- 操作区域 -->
                <div class="actions-section">
                    <h4 class="section-title">
                        <i class="el-icon-download"></i> 下载选项
                    </h4>

                    <div class="action-buttons">
                        <el-button
                                @click="lookSize"
                                icon="el-icon-view"
                                type="info"
                                class="action-btn" :loading=loading>
                            预览大小
                        </el-button>
                        <el-button
                                @click="down"
                                icon="el-icon-download"
                                type="warning"
                                :disabled="!base64Str"
                                class="action-btn" style="margin-left: -1px;">
                            下载压缩图
                        </el-button>
                        <el-button
                                @click="downYuan"
                                icon="el-icon-download"
                                type="success"
                                class="action-btn" style="margin-left: -1px;">
                            下载原图
                        </el-button>
                    </div>

                    <div class="tips-box">
                        <el-alert
                                title="提示"
                                type="info"
                                :closable="false"
                                show-icon>
                            <template slot-scope="">
                                • 需要先点击“预览大小”才能下载压缩图<br>
                                • 质量越低，文件越小<br>
                                • 原图保持最佳质量
                            </template>
                        </el-alert>
                    </div>
                </div>
            </div>
        </el-drawer>
    </div>
</div>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                picSize: '',
                quality: 50,
                imageList: [],
                dialogImageUrl: '',
                dialogVisible: false,
                options: [{value: 'hx', label: '横向'}, {value: 'zx', label: '纵向'}],
                //拼接图片方向
                direction: 'hx',
                // 拼接后的图片
                stitchedImage: '',
                //图片高宽数组
                images: [],
                //路径
                src: '',
                dialogPic: false,
                base64Str: '',
                // 新增状态
                isProcessing: false,
                processingProgress: 0,
                // 图片查看器状态
                imageScale: 1,
                imagePosition: {x: 0, y: 0},
                isDragging: false,
                dragStart: {x: 0, y: 0},
                loading: false
            }
        },
        computed: {
            imageStyle() {
                return {
                    transform: `scale(${this.imageScale}) translate(${this.imagePosition.x}px, ${this.imagePosition.y}px)`,
                    transformOrigin: 'center'
                }
            }
        },
        methods: {
            lookSize() {
                this.loading = true;
                axios.post('http://127.0.0.1:9090/getSize', {
                    base64Str: this.stitchedImage,
                    quality: this.quality
                }).then(res => {
                    this.picSize = res.data.size;
                    this.base64Str = 'data:image/jpeg;base64,' + res.data.base64Str;
                    this.loading = false;
                })
            },
            handleChangeNumber(value) {
                this.quality = value;
            },
            down() {
                if (!this.base64Str) {
                    this.$message({
                        showClose: true,
                        message: '请先查看图片大小',
                        type: 'warning'
                    });
                    return
                }
                let timestamp = new Date().getTime();
                this.downloadFile(timestamp + '.jpg', this.base64Str);
            },
            downYuan() {
                let timestamp = new Date().getTime();
                this.downloadFile(timestamp + '.jpg', this.stitchedImage);
            },
            //下载
            downloadFile(fileName, content) {
                let aLink = document.createElement('a');
                let blob = this.base64ToBlob(content); //new Blob([content]);

                let evt = document.createEvent("HTMLEvents");
                evt.initEvent("click", true, true);//initEvent 不加后两个参数在FF下会报错  事件类型，是否冒泡，是否阻止浏览器的默认行为
                aLink.download = fileName;
                aLink.href = URL.createObjectURL(blob);
                // aLink.dispatchEvent(evt);
                //aLink.click()
                aLink.dispatchEvent(new MouseEvent('click', {bubbles: true, cancelable: true, view: window}));//兼容火狐
            },
            base64ToBlob(code) {
                let parts = code.split(';base64,');
                let contentType = parts[0].split(':')[1];
                let raw = window.atob(parts[1]);
                let rawLength = raw.length;

                let uInt8Array = new Uint8Array(rawLength);

                for (let i = 0; i < rawLength; ++i) {
                    uInt8Array[i] = raw.charCodeAt(i);
                }
                return new Blob([uInt8Array], {type: contentType});
            },

            openDig() {
                this.dialogPic = true;
            }
            ,
            handleClose() {
                this.dialogPic = false;
            }
            ,
            handleRemove(file, fileList) {
                // 如果是数组，说明是从自定义列表中删除
                if (Array.isArray(fileList)) {
                    this.imageList = fileList;
                } else {
                    // 否则是从 ElementUI 组件中删除
                    this.imageList = fileList;
                }

                // 同步移除images数组中的对应项
                const index = this.images.findIndex(img => img.src === file.url);
                if (index > -1) {
                    this.images.splice(index, 1);
                }
            }
            ,
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
                // 重置图片查看器状态
                this.resetImageView();
            }
            ,
            handleChange(file, fileList) {
                this.imageList = fileList;
                this.src = file.url;
                // 上传完成后滚动到图片列表
                this.$nextTick(() => {
                    const uploadedImages = document.querySelector('.uploaded-images');
                    if (uploadedImages && fileList.length > 0) {
                        uploadedImages.scrollIntoView({
                            behavior: 'smooth',
                            block: 'start'
                        });
                    }
                });
            }
            ,
            handleBeforeUpload(file) {
                this.getImageSize(file).then(data => {
                    this.images.push({width: data.width, height: data.height, src: this.src})
                })
            }
            ,
            getImageSize(file) {
                return new Promise((resolve, reject) => {
                    const reader = new FileReader()
                    reader.onload = e => {
                        const image = new Image()
                        image.onload = () => {
                            resolve({
                                width: image.width,
                                height: image.height
                            })
                        }
                        image.src = e.target.result
                    }
                    reader.readAsDataURL(file)
                })
            }
            ,
            async combineImagesToCanvas(imageUrls) {
                const canvas = document.createElement('canvas');
                const ctx = canvas.getContext('2d');
                // 设置canvas尺寸
                if (this.direction === 'hx') {
                    // 水平拼接：宽度为所有图片宽度之和，高度为最高图片的高度
                    const totalWidth = this.images.reduce((sum, img) => sum + img.width, 0);
                    const maxHeight = Math.max(...this.images.map(img => img.height));
                    canvas.width = totalWidth;
                    canvas.height = maxHeight;
                } else {
                    // 垂直拼接：高度为所有图片高度之和，宽度为最宽图片的宽度
                    const totalHeight = this.images.reduce((sum, img) => sum + img.height, 0);
                    const maxWidth = Math.max(...this.images.map(img => img.width));
                    canvas.width = maxWidth;
                    canvas.height = totalHeight;
                }
                // 加载所有图片
                const loadImage = (url) => {
                    return new Promise((resolve, reject) => {
                        const img = new Image();
                        img.crossOrigin = 'anonymous'; // 处理跨域问题
                        img.onload = () => resolve(img);
                        img.onerror = reject;
                        img.src = url;
                    });
                };

                try {
                    // 并行加载所有图片
                    const images = await Promise.all(imageUrls.map(loadImage));
                    let currentX = 0;
                    let currentY = 0;
                    if (this.direction === 'hx') {

                        // 循环绘制图片到canvas
                        images.forEach((img, index) => {
                            ctx.drawImage(
                                img,
                                currentX,  // x坐标
                                0,  // y坐标
                            );
                            currentX += this.images[index].width;
                        });
                    } else {
                        // 循环绘制图片到canvas
                        images.forEach((img, index) => {
                            ctx.drawImage(
                                img,
                                0,  // x坐标
                                currentY,  // y坐标
                            );
                            currentY += this.images[index].height;
                        });
                    }
                    // 返回合成后的图片数据URL
                    return canvas.toDataURL('image/png');
                } catch (error) {
                    console.error('图片加载失败:', error);
                }
            }
            ,
            stitchImages() {
                if (this.imageList == null || this.imageList.length <= 1) {
                    this.$message({
                        showClose: true,
                        message: '请上传至少两张图片',
                        type: 'warning'
                    });
                    return
                }

                // 显示处理状态
                this.isProcessing = true;
                this.processingProgress = 0;

                // 模拟进度条
                const progressInterval = setInterval(() => {
                    this.processingProgress += 10;
                    if (this.processingProgress >= 90) {
                        clearInterval(progressInterval);
                    }
                }, 200);

                this.combineImagesToCanvas(this.imageList.map(item => item.url)).then(dataUrl => {
                    // 完成处理
                    this.processingProgress = 100;
                    setTimeout(() => {
                        this.stitchedImage = dataUrl;
                        this.isProcessing = false;
                        this.processingProgress = 0;
                        this.$message({
                            message: '拼接完成！',
                            type: 'success'
                        });
                        // 拼接完成后滚动到拼接结果卡片
                        this.$nextTick(() => {
                            const resultCard = document.querySelector('.result-card');
                            if (resultCard) {
                                resultCard.scrollIntoView({
                                    behavior: 'smooth',
                                    block: 'start'
                                });
                            }
                        });
                    }, 500);
                });
            },
            // 图片查看器功能
            handleImageWheel(event) {
                event.preventDefault();
                const delta = event.deltaY;
                if (delta > 0) {
                    this.imageScale = Math.max(0.5, this.imageScale - 0.1);
                } else {
                    this.imageScale = Math.min(3, this.imageScale + 0.1);
                }
            },
            startDrag(event) {
                this.isDragging = true;
                this.dragStart = {x: event.clientX, y: event.clientY};
            },
            dragImage(event) {
                if (!this.isDragging) return;
                const deltaX = event.clientX - this.dragStart.x;
                const deltaY = event.clientY - this.dragStart.y;
                this.imagePosition.x += deltaX;
                this.imagePosition.y += deltaY;
                this.dragStart = {x: event.clientX, y: event.clientY};
            },
            endDrag() {
                this.isDragging = false;
            },
            resetImageView() {
                this.imageScale = 1;
                this.imagePosition = {x: 0, y: 0};
            },
            downloadCurrentImage() {
                if (this.dialogImageUrl) {
                    let timestamp = new Date().getTime();
                    this.downloadFile(timestamp + '.jpg', this.dialogImageUrl);
                }
            },
            // 删除图片方法
            removeImage(index) {
                const file = this.imageList[index];
                this.imageList.splice(index, 1);
                // 同步移除images数组中的对应项
                const imgIndex = this.images.findIndex(img => img.src === file.url);
                if (imgIndex > -1) {
                    this.images.splice(imgIndex, 1);
                }
            }
            ,
        },
        mounted() {
            console.log('mounted')
        }
    })
</script>
</body>
</html>